const axios = require("axios");
let ok = 0;
let err = 0;
let token =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTQzMTk4NTUsIm5iZiI6MTY2MzIxNzY1NSwiaWF0IjoxNjYzMjE1ODU1LCJqdGkiOiJDTTpjYXRfbWF0Y2g6bHQxMjM0NTYiLCJvcGVuX2lkIjoiIiwidWlkIjo2NDczMjU4NiwiZGVidWciOiIiLCJsYW5nIjoiIn0.6CKzoxOPJKCtEJVQcEwLMnVGnzhc8x2NoswnfNFGdXU"
let time = 600  // 单位秒
let randomTime = +(Math.random() * 36).toFixed()
let rank_time = randomTime + time
let url1 = `https://cat-match.easygame2021.com/sheep/v1/game/game_over?rank_score=1&rank_state=1&rank_time=${rank_time}&rank_role=1&skin=1`
const reqConfig = {
  headers: {
    Accept: "*/*",
    "Accept-Encoding": "gzip,deflate,br",
    Connection: "keep-alive",
    "User-Agent":
      "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1",
    t: token,
  },
}

const request = axios.create({
  timeout: 60 * 1000 // 请求超时时间
})


function fast(url) {
  request
    .get(
      url,
      reqConfig
    )
    .then((res) => {
      ok++;
      console.log(res.data);
    })
    .catch((error) => {
      err++;
      console.log(error.data, "error");
    })
    .finally(() => {
      console.log(
        `====================羊了个羊勇敢通关${ok}次====================`
      );
      console.log(
        `====================羊了个羊闯关失败${err}次====================`
      );
      if  (url.includes('topic_game_over')) {
        console.log(`'等待${((rank_time + 2)/60).toFixed()}min后开始下一轮'`);
      }
    });
}

let url2 = `https://cat-match.easygame2021.com/sheep/v1/game/topic_game_over?rank_score=1&rank_state=1&rank_time=${rank_time}&rank_role=2&skin=2`

const req = () => {
   fast(url1);
  setTimeout(() => {
    fast(url2);
  }, 3000)
}

setInterval(() => {
  req();
}, rank_time * 1000 + 3000);
req();
